// stores/counter.js
import { defineStore } from 'pinia';
import { computed, ref ,getCurrentInstance} from "vue";
export const userStore = defineStore('user', ()=>{
	const {proxy} = getCurrentInstance()
	const access_token = ref('')
	
	const access_tokenFun=(data)=>{
		access_token.value = data
		uni.setStorageSync('access_token',data)
	}
	const user = ref({})
	const getUser=async()=>{
		const result = await proxy.$api.getUser()
		if(result.code==200){
			console.log('个人资料',result.user);
			user.value = result.user
		}
	}
	const balance = ref({})
	const getBalance=async()=>{
		const result = await proxy.$api.balance()
		if(result.code==200){
			console.log('钱包',result.data);
			balance.value = result.data
			
		}
	}
	
	const carlist = ref([])
	const carfun = async()=>{
		const result =await proxy.$api.ShopCar()
		if(result.code==200){
			console.log('购物车数据',result.rows);
			carlist.value = result.rows
		}
	}

	
	return{access_token,access_tokenFun,getUser,user,getBalance,balance,carfun,carlist}
});